-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Add DocTests to is_palindrome.py #10081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DocTests to is_palindrome.py #10081
Conversation
for more information, see https://pre-commit.ci
…om/SaiHarshaK/Python into u/skottapalli/is_palindrome_update
>>> is_palindrome_dict(\ | ||
ListNode(\ | ||
1, ListNode(2, ListNode(1, ListNode(3, ListNode(2, ListNode(1))))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 discourages backslash line termination in Python because any whitespace to the right of the backslash breaks the script on a change that is invisible to the reader. Also, backslashes are not required inside of (), [], {}...
>>> is_palindrome_dict(\ | |
ListNode(\ | |
1, ListNode(2, ListNode(1, ListNode(3, ListNode(2, ListNode(1))))))) | |
>>> is_palindrome_dict( | |
... ListNode( | |
... 1, ListNode(2, ListNode(1, ListNode(3, ListNode(2, ListNode(1))))) | |
... ) | |
... ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ruff complains that the length of the line is >88 which is why I had to split them into multiple lines.
If i do not add backslash, DocTest assumes ListNode(
is the expected value and thereby the test fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You needed the three dots at the beginning of each continued line as discussed in the doctest docs.
Co-authored-by: Christian Clauss <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy takes some time to get used to but it is quite helpful in the end. If you do new_variable = None
then it wants you to declare the datatype of new_variable
because it refuses to guess.
@cclauss Please check now |
Could you check the comment regarding backslashes? |
I changed the title from doctests to type hints but this looks good to go... Thanks. |
* add doctest ut * test complete * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * format * ruff update * cover line 154 * Update data_structures/linked_list/is_palindrome.py Co-authored-by: Christian Clauss <[email protected]> * use dataclass * pre-commit fix * Fix mypy errors * use future annotations --------- Co-authored-by: Harsha Kottapalli <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
Describe your change:
This PR adds DocTests to the functions in is_palindrome.py to increase its codecoverage from 0% to 96%.
Tested this change locally and can verify that they are passing.
Ref #9943
Checklist: